#include "baseprotocol.h"
#include "baseprotocoldata.h"
#include <QDebug>

BaseProtocol::BaseProtocol(QObject *parent)
    : QObject(parent)
    , m_d(new BaseProtocolData())
{

}

BaseProtocol::BaseProtocol(BaseProtocolData &data, QObject *parent)
    : QObject (parent)
    , m_d(&data)
{

}

BaseProtocol::~BaseProtocol()
{

}

bool BaseProtocol::setConfig(int id, const QVariant &var)
{
    return true;
}

bool BaseProtocol::getConfig(int id, QVariant &var)
{
    return true;
}

bool BaseProtocol::setProtocolCmd(int id, QVariant &var)
{
    return true;
}

bool BaseProtocol::getProtocolCmd(int id, QVariant &var)
{
    return true;
}

void BaseProtocol::setName(const QString &name)
{
    m_name = name;
}

QString BaseProtocol::getName() const
{
    return m_name;
}

ProtocolType BaseProtocol::getProtocolType()
{
    return ProtocolType_YuanRui;
}

void BaseProtocol::onWork(QList<ProtocolPacket> packets)
{
    foreach (auto p, packets)
    {
//        qDebug() << "base protocol" << p.buffer;
        m_d->m_rxPacket = p;
        m_d->m_parser->parse();
    }
}

void BaseProtocol::onBaseTickTimeout()
{

}
